package com.owen.server.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.owen.dao.UserDao;
import com.owen.pojo.User;
import com.owen.server.UserServer;
import com.owen.utils.JxlUtil;
import jxl.write.WriteException;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServerImpl extends ServiceImpl<UserDao, User> implements UserServer {

    @Override
    public List<User> UserList() {
        LambdaQueryWrapper<User> query = new LambdaQueryWrapper<User>();
        return this.list(query);
    }

    @Override
    public void deleteUsers(Long [] ids) {
        removeByIds(Arrays.asList(ids));
    }

    @Override
    public void insertBath(List<User> users) {
        saveBatch(users);
    }

    @Override
    public void exportExcelHandle(HttpServletResponse response) throws IllegalAccessException, IOException, WriteException {
        Map<String,String> header = new LinkedHashMap<String,String>();
        header.put("id","id");
        header.put("name","姓名");
        header.put("age","年龄");
        header.put("address","地址");
        LambdaQueryWrapper<User> query = new LambdaQueryWrapper<User>();
        List<User> data = this.list(query);
        JxlUtil.downExcelAndData(header,data,"用户信息.xls",response);
    }
}
